import collections


class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left: TreeNode = left
        self.right: TreeNode = right


    @staticmethod
    def create_from_list(values: list) -> 'TreeNode':
        deque = []
        for value in values:
            if value is None:
                deque.append(None)
            else:
                deque.append(TreeNode(value))
        j = 1
        for i in range(len(values)):
            if j >= len(values):
                break
            if deque[i] is None:
                continue
            else:
                deque[i].left = deque[j]
                if j+1 >= len(values):
                    break
                deque[i].right = deque[j+1]
                j += 2
        return deque[0]
    
    def __repr__(self):
        return str(self.val)
    
    def print(self):
        deque = []
        values = []
        deque.append(self)
        while deque:
            node = deque.pop(0)
            if node:
                values.append(node.val)
                deque.append(node.left)
                deque.append(node.right)
            else:
                values.append(None)
        print(values)
        
